package com.mapas;

import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class dibujo extends Overlay
{
	ArrayList<oMercado> mercados;
	
	
	private final int mRadius = 5;


	private RectF oval;


	private RectF backRect;
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) 
	{
		Projection projection = mapView.getProjection();
		if (shadow == false) 
		{
//			// Get the current location
//			Double latitude = location.getLatitude()*1E6;
//			Double longitude = location.getLongitude()*1E6;
			int cantidad=mercados.size();
			GeoPoint geoPoint;
			for (int i=0; i<cantidad;i++)
			{
				oMercado oMercado=(oMercado)mercados.get(i);
				geoPoint = new
				GeoPoint(oMercado.getLatitud().intValue(),oMercado.getLongitud().intValue());
				// Convert the location to screen pixels
				Point point = new Point();
				projection.toPixels(geoPoint, point);
				setOval(new RectF(point.x - mRadius, point.y - mRadius,
				point.x + mRadius, point.y + mRadius));
				// Setup the paint
				Paint paint = new Paint();
				paint.setARGB(250, 255, 255, 255);
				paint.setAntiAlias(true);
				paint.setFakeBoldText(true);
				Paint backPaint = new Paint();
				backPaint.setARGB(175, 50, 50, 50);
				backPaint.setAntiAlias(true);
				setBackRect(new RectF(point.x + 2 + mRadius,
				point.y - 3*mRadius,
				point.x + 65, point.y + mRadius));
				// Draw the marker
				//canvas.drawOval(oval, paint);
				//canvas.drawRoundRect(backRect, 5, 5, backPaint);
				canvas.drawText(oMercado.getNombre(),
				point.x + 2*mRadius, point.y,
				paint);
				canvas.drawBitmap(oMercado.getIcono(), point.x+mRadius, point.y, null);				
	            
			}
			
		}
		super.draw(canvas, mapView, shadow);
	}
	
	@Override
	public boolean onTap(GeoPoint point, MapView mapView) 
	{	
	
		return false;
	}

	public void setOval(RectF oval) {
		this.oval = oval;
	}

	public RectF getOval() {
		return oval;
	}

	public void setBackRect(RectF backRect) {
		this.backRect = backRect;
	}

	public RectF getBackRect() {
		return backRect;
	}

}
